package business;
import java.util.*;

import persistence.*;

/*
 * Singleton Class
 */
public class EventBook 
{
	//member variables
	private ArrayList<Event> Events;
	private static EventBook Instance;
	
	//constructor
	private EventBook()
	{
		Events = new ArrayList<Event>(30);
		LoadFromStorage();
		
	}
	
	//methods
	/*
	 * Singleton Class Method
	 */
	public static EventBook GetInstance()
	{
		if(Instance==null)
		{
			Instance = new EventBook();
			return Instance;
		}
		
		else
		{
			return Instance;
		}
	}
	

	private void LoadFromStorage()
	{
		ArrayList<EventFascade> temp;
		temp = EventTDG.FindAll();

		HallBook HallBookInstance = HallBook.GetInstance();
		
		for(EventFascade EF : temp)
		{
			Hall EventsHall = HallBookInstance.Find(EF.getHallID());
			Events.add(new Event(EF.getName(),EF.getStartTime(),EF.getEndTime(),EF.getMaxCapacity(),EF.getStatus(),EventsHall)); 
		}
		

	}

	//ACCESSORS AND MUTATORS
	
	public ArrayList<Event> getEvents() {
		return Events;
	}

	public void setEvents(ArrayList<Event> events) {
		Events = events;
	}

}
